package com.zhanglinwei.openApiClient.client;

import com.zhanglinwei.openApiClient.model.entity.OpenApiEntity;
import com.zhanglinwei.openApiClient.model.request.OpenApiRequest;
import com.zhanglinwei.openApiClient.model.response.lambda.LambdaOpenApiResponse;
import com.zhanglinwei.openApiClient.model.response.OpenApiResponse;
import com.zhanglinwei.openApiClient.wrapper.AbstractLambdaWrapper;

import java.util.List;
import java.util.Optional;

public interface OpenApiClient {

    <R extends OpenApiResponse> R apiCodeQuery(OpenApiRequest<R> request);
    <T, R extends LambdaOpenApiResponse<T>, E extends OpenApiEntity<R>> Optional<T> selectOne(AbstractLambdaWrapper<E, ? extends AbstractLambdaWrapper<E, ?>> lambdaWrapper);
    <T, R extends LambdaOpenApiResponse<T>, E extends OpenApiEntity<R>> Optional<T> selectOne(AbstractLambdaWrapper<E, ? extends AbstractLambdaWrapper<E, ?>> lambdaWrapper, boolean throwError);
    <T, R extends LambdaOpenApiResponse<T>, E extends OpenApiEntity<R>> List<T> selectList(AbstractLambdaWrapper<E, ? extends AbstractLambdaWrapper<E, ?>> lambdaWrapper);
    <T, R extends LambdaOpenApiResponse<T>, E extends OpenApiEntity<R>> R selectPage(AbstractLambdaWrapper<E, ? extends AbstractLambdaWrapper<E, ?>> lambdaWrapper);

    static OpenApiClient createClient(String serverAddress, String appKey, String appSecret) {
        return new DefaultOpenApiClient(serverAddress, appKey, appSecret);
    }
}
